package org.elanfox.intellicommunity.biz.dto.msg;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.elanfox.intellicommunity.common.ienum.MsgEnums;
import org.elanfox.intellicommunity.data.base.dto.BaseSaveDTO;
import org.elanfox.intellicommunity.msg.dto.RawTagDTO;

import java.time.LocalDateTime;

/**
 * @author allan
 * @version 1.0.0
 * @date 2019/12/19
 */
@Data
@NoArgsConstructor
public class MsgSaveDTO implements BaseSaveDTO {
    private static final long serialVersionUID = -6020774226023184969L;

    /**
     * 基站编号
     */
    private long stationId;
    /**
     * 定位器编号
     */
    private long locatorId;
    /**
     * 卡编号
     */
    private long cardId;

    /**
     * 时间
     */
    private LocalDateTime dateTime;
    private MsgEnums.AlarmType alarmType;

    public MsgSaveDTO(RawTagDTO tagDTO) {
        this.stationId = tagDTO.getDeviceAddr();
        this.locatorId = tagDTO.getNewTriggerId();
        if (locatorId == 0) {
            this.locatorId = tagDTO.getOldTriggerId();
        }
        this.cardId = tagDTO.getTagId();
        this.dateTime = tagDTO.getTime();
        this.alarmType = MsgEnums.AlarmType.NO_ALARM;
        if (tagDTO.isBatteryNotEnough()) {
            this.alarmType = MsgEnums.AlarmType.BATTERY_ALARM;
        }
        if (tagDTO.isAlarmedButton()) {
            this.alarmType = MsgEnums.AlarmType.ALARM_BUTTON;
        }
    }

    @Override
    public String toString() {
        return "MsgSaveDTO{" +
                "stationId=" + stationId +
                ", locatorId=" + locatorId +
                ", cardId=" + cardId +
                '}';
    }
}
